package com.bysj.lms.controller;


import com.bysj.lms.common.ResultModel;
import com.bysj.lms.pojo.entity.Class;
import com.bysj.lms.service.IClassService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaojiakai
 * @since 2022-02-04
 */
@Api(tags = "班级管理")
@RestController
@RequestMapping("/class")
public class ClassController {

    @Autowired
    IClassService classService;


    @ApiOperation(value = "分页查询班级",notes = "name为空总查询，name不为空模糊查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页"),
            @ApiImplicitParam(name = "count",value = "页的大小"),
            @ApiImplicitParam(name = "name",value = "班级名")
    })
    @GetMapping("/find")
    public ResultModel find(Integer page,Integer count,String name){
        PageInfo pageInfo = classService.findByPage(name, page, count);
        return ResultModel.success("查询成功",pageInfo);
    }
    
    @ApiOperation("添加班级")
    @PostMapping("/add")
    public ResultModel add(@RequestBody Class classInfo){
        boolean save = classService.save(classInfo);
        return save?ResultModel.success():ResultModel.failure();
    }
    
    @ApiOperation("修改班级")
    @PutMapping("/edit")
    public ResultModel edit(@RequestBody Class classInfo){
        boolean update = classService.updateById(classInfo);
        return update?ResultModel.success():ResultModel.failure();
    }
    
    @ApiOperation("删除班级")
    @DeleteMapping("delete")
    public ResultModel delete(Integer id){
        boolean delete = classService.removeById(id);
        return delete?ResultModel.success():ResultModel.failure();
    }
}

